//1.创建format函数，格式化当前时间
//在形参中设置具体的时间格式
/*
function format(str){
  var now = new Date();
  var year = now.getFullYear();
  var month = now.getMonth()+1;
  var date = now.getDate();
  //根据参数所传递的时间格式来进行具体的操作
  if(str == 'yyyy-mm-dd'){
    return year + '-' + month + '-' + date;
  }else if(str == 'mm/dd/yyyy'){
    return month + '/' + date + '/' + year;
  }
}
var res1 = format('yyyy-mm-dd');
console.log(res1);
var res2 = format('mm/dd/yyyy');
console.log(res2);
*/
//2.员工到期时间
//入职时间2012-6-30
//var workTime = new Date(2012,5,30);
var workTime = new Date('2012/6/30');
//复制时间对象
var reworkTime = new Date(workTime);
//3年后合同到期时间
reworkTime.setFullYear(reworkTime.getFullYear()+3);
//续签时间，复制合同到期时间对象
var newWorkTime = new Date(reworkTime);
//提前一个月
newWorkTime.setMonth(newWorkTime.getMonth()-1);
//如果是周日，提前2天，周六，提前一天
if(newWorkTime.getDay()==0){
   newWorkTime.setDate(newWorkTime.getDate()-2);
}
if(newWorkTime.getDay()==6){
   newWorkTime.setDate(newWorkTime.getDate()-1);
}
//提醒时间，复制续签时间
var remindTime = new Date(newWorkTime);
//提前一周
remindTime.setDate(remindTime.getDate()-7);

console.log('入职时间'+workTime.toLocaleString());
console.log('到期时间'+reworkTime.toLocaleString());
console.log('续签时间'+newWorkTime.toLocaleString());
console.log('提醒时间'+remindTime.toLocaleString());





